package cn.nohan.funplay.module.member.mongo.config;

import com.mongoplus.mapping.MongoConverter;
import com.mongoplus.strategy.conversion.ConversionStrategy;
import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author caozhipeng
 * @date 2025/7/22
 */
@Slf4j
@Component
public class MongoDBGeoJsonPointConversionStrategy implements ConversionStrategy<GeoJsonPoint> {

    @Override
    public GeoJsonPoint convertValue(Object fieldValue, Class<?> fieldType, MongoConverter mongoConverter) throws IllegalAccessException {
        GeoJsonPoint geoJsonPoint = null;
        if (fieldValue.getClass().equals(Document.class)&&fieldType.equals(GeoJsonPoint.class)){
            Document document=(Document) fieldValue;
            geoJsonPoint = new GeoJsonPoint(document.getDouble("x"),document.getDouble("y"));
        }
        return geoJsonPoint;
    }


}
